<?php $this->load->view('templates/backend/header'); ?>
<h3><?php echo $this->lang->line('telecom');?></h3>
<style>
    .fone_num_cls{
        width:20%;  vertical-align: top;
    }
</style>
<?php if (isset($flash_message)  && $flash_message!=NULL ): ?>
<div class="alert alert-success"><a class="close" sales-dismiss="alert">x</a><strong><?php echo $flash_message; ?></strong></div>
<?php endif; ?>
<div class="well">
    <?php echo form_open('auth/telecom/sendsms/',array('id'=>'ajaxform'));?>
        <div class="tab-content">	
            <div class="tab-pane active" id="main">
                 <?php
                        //ho ten
                    echo form_label($this->lang->line('phone'), 'phone');
                    echo form_input(array('name' => 'phone', 'id' => 'phone', 'value' => '','required'=>'required','placeholder'=>$this->lang->line('phone')));
                    echo form_error('phone');

                     //Ghi chú
                    echo form_label($this->lang->line('message'), 'message');
                    echo form_textarea(array('name' => 'message', 'id' => 'message', 'value' => $this->lang->line('prefixMsg'),'required'=>'required','rows'=>'10','maxlength'=>'177','placeholder'=>$this->lang->line('limit160')));
                    echo form_error('message');
                    ?>
            </div>
        </div>
        <div class="top-button">
                <?php echo form_button(array('id' => 'submit', 'value' => 'Update', 'name' => 'submit', 'type' => 'submit', 'content' => $this->lang->line('send'),'class' => 'btn btn-success')); ?>
                <a href="<?php echo site_url('auth/telecom'); ?>" class="btn"><?php echo $this->lang->line('cancel')?></a>
        </div>
    <?php echo form_close();?>
    <span id="simple-msg"></span>
</div>

<?php $this->load->view('templates/backend/footer'); ?>

<script>
$(document).ready(function() {
        $("#ajaxform").submit(function(e)
        {
            var phone        =   $("#phone").val();
            var message     =   $("#message").val();
            if(phone =="" || message == "" || message.length > 160){
                alert("Vui lòng xem lại thông tin nhập chưa chính xác");return false;
            }
            $('button[type="submit"]').attr('disabled','disabled');
            $("#loading-image").show();
            var postData    = $(this).serializeArray();
            var formURL     = $(this).attr("action");
            setTimeout(function () {
                $.ajax(
                    {
                        url : formURL,
                        type: "POST",
                        data : postData,
                        cache: true,
                        beforeSend: function(){
                                $("#loading-image").hide();
                                $("#control-image").show();
                                $('button[type="submit"]').attr('disabled','disabled');
                        },
                        success:function(data) 
                        {
                            setTimeout(function () {
                                
                                $("#control-image").hide();
                                var responseData    = JSON.parse(data);
                                if(responseData.error == 1){
                                    $('button[type="submit"]').removeAttr('disabled');
                                    alert(responseData.result);
                                } else {
                                    $('button[type="submit"]').attr('disabled','disabled');
                                    alert('Gởi tin nhắn thành công!');
                                }
                                return false;
                            },2000);
                               
                        },
                        error: function() 
                        {
                                alert("Gởi tin nhắn thất bại!LỖI");
                        }
                    });
            }, 2000);
            e.preventDefault();	//STOP default action
        });
        
        function is_float(mixed_var) {
            return +mixed_var === mixed_var && (!isFinite(mixed_var) || !! (mixed_var % 1));
        }
});
</script>